package utils

import (
	"encoding/json"
	"io/ioutil"
	"zinx/ziface"
)

type GlobalObj struct {
	TcpServer      ziface.IServer
	Host           string
	Port           int
	Name           string
	Version        string
	MaxPackageSize uint32
	MaxConn        uint
}

var GlobalObject *GlobalObj

func (g *GlobalObj) Reload() {
	data, err := ioutil.ReadFile("config/zinx.json")
	if err != nil {
		panic(err)
	}
	err = json.Unmarshal(data, &GlobalObject)
	if err != nil {
		panic(err)
	}
}

func init() {
	GlobalObject = &GlobalObj{
		Name:           "Zinx Server",
		Version:        "V0.4",
		Host:           "0.0.0.0",
		Port:           7777,
		MaxPackageSize: 4096,
		MaxConn:        1000,
	}
	GlobalObject.Reload()
}
